function intersectionSizeTwo(intervals) {
  // 按右端点升序，右端点相同则左端点降序排序
  intervals.sort((a, b) => {
    if (a[1] !== b[1]) return a[1] - b[1];
    return b[0] - a[0];
  });

  const selected = [];
  for (const [start, end] of intervals) {
    let count = 0;
    // 统计当前区间内已选中的点数量
    for (const num of selected) {
      if (num >= start && num <= end) {
        count++;
        if (count === 2) break;
      }
    }
    // 需要补充的点数量
    let need = 2 - count;
    let current = end;
    while (need > 0) {
      // 确保添加的点不在已选中的列表中
      if (!selected.includes(current)) {
        selected.push(current);
        need--;
      }
      current--;
    }
  }
  return selected.length;
}
